package com.teamall.web.xtgl.controller;

import com.teamall.core.common.JModelAndView;
import com.teamall.framework.exception.BaseAppException;
import com.teamall.framework.util.UploadFileUtil;
import com.teamall.web.base.vo.ResResult;
import com.teamall.web.sys.db.po.SysPhotoPO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * ${DESCRIPTION}
 *
 * @author
 * @create 2017-07-08 23:31
 **/
@Controller
@RequestMapping("/xtgl")
public class XtglController {
    @RequestMapping("/main")
    public ModelAndView index() {
        ModelAndView modelAndView = new JModelAndView("/xtgl/xtgl_main");
        return modelAndView;
    }

    /**
     * 保存文件
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/uploadfiles", consumes = "multipart/form-data")
    @ResponseBody
    public ResResult uploadfiles(HttpServletRequest request) throws BaseAppException {
        ResResult resResult = new ResResult();
        List<Map> resultList = UploadFileUtil.saveFiles(request);
        resResult.setMsg("文件上传成功");
        resResult.setRspData(resultList);
        for (Map<String, String> map : resultList) {
            SysPhotoPO po = new SysPhotoPO();
            po.setPhotoCode(map.get("imgId"));
            po.setFilePath(map.get("realPath"));
        }
        return resResult;
    }
}
